<?php

namespace App\Services;


use App\Models\CourseSectionQuestionAnswer;
use App\Models\CourseSectionQuestionAnswerBack;

class CourseSectionQuestionAnswerBackService  extends BaseService
{
    /**
     * 获取列表
     * @return
     */
    public function list($sort,$order, $answers_id,$from_users_id,$to_users_id) {
        $query = CourseSectionQuestionAnswerBack::leftJoin('users as from_users', 'from_users.id', '=', 'course_section_question_answer_backs.from_users_id')
            ->leftJoin('users as to_users', 'to_users.id', '=', 'course_section_question_answer_backs.to_users_id')
            ->select('course_section_question_answer_backs.*',
                'from_users.pic as from_users_pic','from_users.name as from_users_name',
                'to_users.pic as to_users_pic','to_users.name as to_users_name'
            );

        if(!empty($answers_id)){
            $query->where('answers_id', $answers_id);
        }
        if(!empty($from_users_id)){
            $query->where('from_users_id', $from_users_id);
        }
        if(!empty($to_users_id)){
            $query->where('to_users_id', $to_users_id);
        }
        return $query->orderBy($sort,$order)->get();
    }
}
